#include <iostream>
class Foo {
public:
    Foo(int a = 0) : _a(a) {
        std::cout << "Foo::Foo(int)" << std::endl;
    }

    ~Foo() {
        std::cout << "Foo::~Foo()" << std::endl;
    }

    Foo(const Foo& other) : _a(other._a) {
        std::cout << "Foo::Foo(const Foo&)" << std::endl;
    }

    Foo(Foo&& other) : _a(other._a) {
        std::cout << "Foo::Foo(Foo&&)" << std::endl;
    }

    Foo& operator=(const Foo& other) {
        std::cout << "Foo::operator=(const Foo&)" << std::endl;
        if (this == &other) return *this;
        _a = other._a;
        return *this;
    }

    Foo& operator=(Foo&& other) {
        std::cout << "Foo::operator=(Foo&&)" << std::endl;
        if (this == &other) return *this;
        _a = other._a;
        return *this;
    }

    int a() const {
        return _a;
    }

private:
    int _a;
};

Foo CreateFoo(Foo foo) {  // 3. Foo(const Foo &) 拷贝构造
    int val = foo.a();
    Foo tmp = val;  // 4. Foo(int) 普通构造
    return tmp;
}  // 6. 7. 两次析构 ~Foo()

int main() {
    Foo f1;  // 1. Foo(int) 普通构造
    Foo f2;  // 2. Foo(int) 普通构造
    f2 = CreateFoo(f1);  // 5. operator=(Foo&&) 移动赋值
    return 0;
} // 8. 9. 两次析构 ~Foo()